package com.lw.smartdevice.utils;

import com.lw.smartdevice.pojo.SysUserInfo;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Administrator
 * @version 1.0
 * @description:
 * @date 2022/3/20 19:26
 */
public class SecurityUtils {
    public static SysUserInfo getLoginUser(){

        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            return (SysUserInfo) request.getSession().getAttribute("user");
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    public static SysUserInfo getLoginUserWithtest(){
        SysUserInfo sysUserInfo=new SysUserInfo();
        sysUserInfo.setUsername("xiaomei");
        return sysUserInfo;
    }
}
